@import '../global';

/**
 * @class Ext.dataview.List
 */

/**
 * @var {color} $list-color
 * Text color for list rows.
 */
$list-color: #000 !default;

/**
 * @var {color} $list-bg-color
 * Background-color for list rows.
 */
$list-bg-color: #f7f7f7 !default;

/**
 * @var {color} $include-list-highlights
 * Optionally disable all list gradients, text-shadows, and box-shadows. Useful for CSS debugging,
 * non-performant browsers, or minimalist designs.
 */
$include-list-highlights: $include-highlights !default;

/**
 * @var {boolean} $list-zebrastripe
 * Optionally zebra-stripe the list (alternating background colors).
 */
$list-zebrastripe: false !default;

/**
 * @var {color} $list-pressed-color
 * Background-color for pressed list rows.
 */
$list-pressed-color: lighten($active-color, 50%) !default;

/**
 * @var {color} $list-active-color
 * Background-color for selected list rows.
 */
$list-active-color: $active-color !default;

/**
 * @var {string} $list-active-gradient
 * Gradient style for selected list rows.
 */
$list-active-gradient: $base-gradient !default;

/**
 * @var {color} $list-header-bg-color
 * Background-color for list header rows (in grouped lists).
 */
$list-header-bg-color: lighten(saturate($base-color, 10%), 20%) !default;

/**
 * @var {string} $list-header-gradient
 * Gradient style for list header rows (in grouped lists).
 *
 * See {@link Global_CSS#background-gradient background-gradient}.
 */
$list-header-gradient: $base-gradient !default;

/**
 * @var {measurement} $list-disclosure-size
 * Default size (width/height) for disclosure icons.
 */
$list-disclosure-size: 1.7em;

/**
 * @var {measurement} $list-disclosure-round-size
 * Default size (width/height) for disclosure icons in a list with a 'round' ui.
 */
$list-disclosure-round-size: 1.5em;

/**
 * Includes default list styles.
 */
@mixin sencha-list {
  .x-list {
    position: relative;
    background-color: $list-bg-color;

    .x-list-inner {
      width: 100%;
    }

    .x-list-disclosure {
      position: absolute;
      bottom: 0.44em;
      right: 0.44em;
    }

    .x-list-disclosure {
      overflow: visible;
      -webkit-mask: 0 0 theme_image($theme-name, "disclosure.png") no-repeat;
      -webkit-mask-size: $list-disclosure-size;
      @include background-gradient(saturate($active-color, 10%));
      width: $list-disclosure-size;
      height: $list-disclosure-size;
    }

    &.x-list-indexed .x-list-disclosure {
      margin-right: 1em;
    }

    .x-item-selected .x-list-disclosure {
      background: #fff none;
    }

    .x-list-item {
      position: relative;
      color: $list-color;

      .x-list-item-label {
        min-height: $global-row-height;
        padding: 0.65em 0.8em;
      }

      &.x-item-pressed {
        .x-list-item-label {
          background: $list-pressed-color none;
        }
      }

      &.x-item-selected {
        .x-list-item-label {
          @include background-gradient($list-active-color, $list-active-gradient);
          @include color-by-background($list-active-color);
          @include bevel-by-background($list-active-color);
        }
      }
    }
  }

  .x-list-header {
    position: relative;
  }

  .x-list-header-swap {
    position: absolute;
    left: 0;
    width: 100%;
    z-index: 1;
  }

  .x-ios .x-list-header-swap {
    @include transform(translate3d(0, 0, 0));
  }

  .x-list-normal {

    .x-list-header {
      @include background-gradient($list-header-bg-color, $list-header-gradient);
      @include color-by-background($list-header-bg-color, 30%);
      @include bevel-by-background($list-header-bg-color);
      border-top: 1px solid $list-header-bg-color;
      border-bottom: 1px solid darken($list-header-bg-color, 20%);
      font-weight: bold;
      font-size: 0.8em;
      padding: 0.2em 1.02em;
      @include bevel-by-background($list-header-bg-color);
    }

    .x-list-item {

      @if $list-zebrastripe {
        .x-list-item-label {
          border-top: 1px solid transparent;
        }
        &:nth-child(even) .x-list-item-label {
          background-color: darken($list-bg-color, 5%);
        }
        &:last-child:nth-child(odd) .x-list-item-label {
          border-bottom: 1px solid darken($list-bg-color, 5%);
        }
      } @else {
        .x-list-item-label {
          border-top: 1px solid darken($list-bg-color, 10%);
        }
        &:last-child .x-list-item-label {
          border-bottom: 1px solid darken($list-bg-color, 10%);
        }
      }

      &:first-child .x-list-item-label {
        border-top: 0;
      }

      @if $include-list-highlights {
        &.x-item-pressed .x-list-item-label {
          border-top-color: $list-pressed-color;
          background-color: $list-pressed-color;
        }

        &.x-item-selected .x-list-item-label {
          border-top-color: $list-active-color;
          border-bottom-color: darken($list-active-color, 15%);
        }
      }
    }


  }

  .x-list-round {
    .x-scroll-view {
      background-color: #EEEEEE !important; // @todo No !important plz
    }

    .x-list-disclosure {
      overflow: hidden;
      -webkit-mask: 0 0 theme_image($theme-name, "disclosure2.png") no-repeat;
      -webkit-mask-size: $list-disclosure-round-size;
      @include background-gradient(lighten(desaturate($base-color, 10), 10));
      width: $list-disclosure-round-size;
      height: $list-disclosure-round-size;
      bottom: 0.5em;
    }

    .x-list-header {
      color: #777;
      font-size: 1em;
      font-weight: bold;
      padding-left: 26px;
      line-height: 1.7em;
//      background: rgba(238,238,238,.8);
      @include background-image(linear-gradient(top, rgba(238,238,238,1), rgba(238,238,238,.9) 30%, rgba(238,238,238,.4)));
    }

    .x-list-container {
      padding: 13px 13px 0 13px;

      .x-list-header {
        padding-left: 13px;
        background-image: none;
      }
    }

    &.x-list-ungrouped,
    &.x-list-grouped {
      .x-list-item-label {
        border: solid #DDDDDD;
        border-width: 1px 1px 0 1px;
        background: #fff;
      }
    }

    &.x-list-ungrouped {
      .x-list-item {
        &:first-child {
          .x-list-item-label {
            @if $include-border-radius { @include border-top-radius($form-fieldset-radius); }
          }
        }

        &:last-child {
          .x-list-item-label {
            @if $include-border-radius { @include border-bottom-radius($form-fieldset-radius); }
            border-width: 1px;
          }

          margin-bottom: 13px;
        }
      }
    }

    &.x-list-grouped {
      .x-list-header-item {
        .x-list-item-label {
          @if $include-border-radius { @include border-top-radius($form-fieldset-radius); }
        }
      }

      .x-list-footer-item {
        margin-bottom: 13px;

        .x-list-item-label {
          border-width: 1px;
          @if $include-border-radius { @include border-bottom-radius($form-fieldset-radius); }
        }
      }
    }
  }

  .x-dataview-inlineblock {
    .x-dataview-item {
      display: inline-block !important;
    }
  }

  .x-dataview-nowrap {
    .x-dataview-container {
      white-space: nowrap !important;
    }
  }

  .x-list-inlineblock {
    .x-list-item {
      display: inline-block !important;
    }
  }

  .x-list-nowrap {
    .x-list-inner {
      width: auto;
    }
    .x-list-container {
      white-space: nowrap !important;
    }
  }
}

@mixin sencha-list-paging {
  .x-list-paging {
    height: 50px;
    .x-loading-spinner {
      display: none;
      margin: auto;
    }

    .x-list-paging-msg {
      text-align: center;
      color: $active-color;
      padding-top: 10px;
      @if $include-border-radius { @include border-radius(6px); }
    }

    &.x-loading {
      .x-loading-spinner {
        display: block;
      }

      .x-list-paging-msg {
        display: none;
      }
    }
  }
}

@mixin sencha-list-pullrefresh {
  .x-list-pullrefresh {
    @include display-box;
    @include box-orient(horizontal);
    @include box-align(center);
    @include box-pack(center);
    position: absolute;
    top: -5em;
    left: 0;
    width: 100%;
    height: 4.5em;

    .x-loading-spinner {
      display: none;
    }
  }

  .x-list-pullrefresh-arrow {
    width: 2.5em;
    height: 4.5em;

    background: center center theme_image($theme-name, "pullarrow.png") no-repeat;
    background-size: 2em 3em;
    /*-webkit-transition-property: -webkit-transform;*/
    /*-webkit-transition-duration: 200ms;*/
    @include rotate(0deg);
  }

  .x-list-pullrefresh-release .x-list-pullrefresh-arrow {
    @include rotate(-180deg);
  }

  .x-list-pullrefresh-wrap {
    width: 20em;
    font-size: 0.7em;
  }

  .x-list-pullrefresh-message {
    font-weight: bold;
    font-size: 1.3em;
    margin-bottom: 0.1em;
    text-align: center;
  }

  .x-list-pullrefresh-updated {
    text-align: center;
  }

  .x-list-pullrefresh-loading {
    /*position: relative;*/
    /*top: 0;*/

    /*.x-loading-spinner {
      display: block;
    }

    .x-list-pullrefresh-arrow {
      display: none;
    }*/
  }
}
